<table class="form-table-without-line">
    <tr>
        <th>期号</th>
        <td>
            <input type="text" class="am-form-field issue" placeholder="输入待设置的期数" />
        </td>
    </tr>
    <tr>
        <th>开奖结果</th>
        <td>
            <input type="text" class="am-form-field result" placeholder="5个开奖号码，请用,隔开" />
            <button type="button" class="save">保存</button>
        </td>
    </tr>
</table>

<script src="../public/all/js/result.js"></script>
<script>
    // 将最近一期的期号和开奖时间填入
    var game = 'gd115';
    Result.switchGame(game);
    Result.cb = function() {
        var curr = Result.curr();
        if (!curr) return;

        $(".issue").val(curr.issue);
    };

    $("button.save").click(function() {
        var arr = $("input.result").val().trim().split(",");
        if (arr.length != 5) {
            alert2("开奖号码应该为5个！", true);
            return;
        }

        for (var i = 0; i < arr.length; i++) {
            var n = arr[i];
            if (n == '' || parseInt(n) < 1 || parseInt(n) > 11) {
                alert2("开奖结果数字应该为1-11。", true);
                return;
            }
            n = parseInt(n);
            arr[i] = n;

            // 确保数字不重复
            for (var j = 0; j < i; j++) {
                if (arr[j] == arr[i]) {
                    alert2("开奖数字不能重复！", true);
                    return;
                }
            }
        } 

        // 数字处理下（前加0）
        var arr2 = [];
        for (var i in arr) {
            arr2.push(arr[i] >= 10 ? "" + arr[i]: "0" + arr[i]);
        }

        // 保存
        startLoading();
        CMD.set_lottery_result(game, $(".issue").val().trim(), arr2, function() {
            stopLoading();
            alert2("设置成功！");
        });
    });
</script>
